package com.project.communitymanagement.common;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.security.core.context.SecurityContextHolder;

import java.io.Serializable;
import java.util.Date;
import org.springframework.security.core.userdetails.User;

/**
 * @ProjectName: hotelNew
 * @Package: com.setup.mysql.common
 * @ClassName: BaseEntity
 * @Author: "XGP"
 * @Description:
 * @Date: 2021/09/13 11:30
 * @Version: 1.0
 */
@Data
public class BaseEntity implements Serializable {

    private String id;
    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date create_date;
    /**
     * 创建人
     */
    private String create_user = SecurityContextHolder.getContext().getAuthentication() != null
            ? SecurityContextHolder.getContext().getAuthentication().getPrincipal() instanceof User
            ? ((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername()
       /*     : "test_user_admin"
            : "test_user_admin"; */
            : null
            : null;

    public void saveInit() {
        this.create_date = new Date();
    }
}

